<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/9
 * Time: 23:39
 */
class QuickSallAction extends HomeAction
{
    public function add(){
        if(IS_POST){
            $product_amount = 880;
            $post = I("post.");
            $height = I("post.height");
            $weight = I("post.weight");
            $shoulder = I("post.shoulder");
            $stomach = I("post.stomach");
            $chest = I("post.chest");
            $posture = I("post.posture");
            $special_request = I("post.special_request");
            $attr = I("post.product_attr");
            $product_user_size = D('user_size');
            $where['height'] = array('elt', $height);
            $where['height2'] = array('egt', $height);
            $where['weight'] = array('elt', $weight);
            $where['weight2'] = array('egt', $weight);
            $product_user_size->where($where);
            $info = $product_user_size->find();
            if($info){
                $data['measure_name'] = '自动匹配';
                $data['measure']['shoulder']['type'] = !empty($shoulder) ? $shoulder : 3;
                $data['measure']['posture']['type'] = !empty($posture) ? $posture : 3;
                $data['measure']['chest']['type'] = !empty($chest) ? $chest : 3;
                $data['measure']['stomach']['type'] = !empty($stomach) ? $stomach : 3;
                $data['measure']['height']['cm'] = $height;
                $data['measure']['weight']['kg'] = $weight;
                $data['measure']['neck']['cm'] = $info['neck'];
                $data['measure']['jacket_back']['cm'] = $info['shoulder'];   //肩宽
                $data['measure']['bicep']['cm'] = $info['bicep'];
                $data['measure']['sleeve']['cm'] = $info['outside_sleeve'];
                $data['measure']['wrist']['cm'] = $info['wrist'];
                $data['measure']['shirt']['cm'] = $info['forepart_length'];
                $data['measure']['chest']['cm'] = $info['circumference'];
                $data['measure']['stomach']['cm'] = $info['waistline'];  //腰围   肚围
                $data['measure']['waist']['cm'] = $info['pants_hips'];  //  裤腰围   下摆
                $data['measure']['pants_hips']['cm'] = ""; //臀围
                $data['measure']['pants']['cm'] = "";
                $data['measure']['crotch']['cm'] = "";
                $data['measure']['thigh']['cm'] = "";
                $data['measure']['knee']['cm'] = "";
                $mid = MeasureModel::add_measure_data($data);
            }else{
                $mid = 0;
            }
            $order_data = array();
            $order_data['product_amount'] = $product_amount;
            $order_data['order_amount'] = $product_amount;
            $order_data['pay_amount'] = $product_amount;
            $order_data['delivery_first_name'] = $post['name'];
            $order_data['delivery_phone'] = $post['phone'];


            $order_data['delivery_postcode'] = $post['delivery_postcode'];
            $order_data['delivery_email'] = $post['delivery_email'];
            $order_data['delivery_cid'] = $post['delivery_cid'];
            $order_data['delivery_pid'] = $post['delivery_pid'];
            $order_data['delivery_province'] = $post['delivery_province'];
            $order_data['delivery_city'] = $post['delivery_city'];
            $order_data['delivery_address'] = $post['delivery_address'];
            $order_data['delivery_address2'] = $post['delivery_address2'];
            $order_data['delivery_cid'] = 44;
            $order_data['payment_method'] = 'Alipay';
            $order_data['shipping_method'] = '';
            $order_data['delivery_email'] = '';



            $order_id = OrderModel::insert_order($order_data);


            $set = array(
                'order_id' => $order_id,
                'product_id' => 1993,
                'product_sn' => "SN0000001993",
                'product_name' => "全棉免烫白衬衫",
                'sell_price' => "0",
                'qty' => 1,
                'weight' => 0,
                'total_weight' => 0,
                'pay_price' => $product_amount,
                'total_amount' => $product_amount,
                'custom_type' => 2,
                'chima' => "",
                'car_type' => 0,
                'designer_id' => 0,
                'attr' => $attr,
                'measure_id' => $mid,
                'special_request_1' => $special_request,
                'pants_price' => 0,
                'pants_qty'   => 0,
            );
            $orderitemid = OrderModel::insert_order_items($order_id, $set);
            $this->success("下单成功", url('QuickSall/add'));

        }else{
            $this->display('add');
        }

    }
}